package com.example.comm.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.comm.Bean.Post;
import com.example.comm.R;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;

public class Receive extends AppCompatActivity {
    private TextView username,content,time;
    private ImageView back;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive);

        initView();

        initData();
        //监听返回
       back.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               finish();
           }
       });
    }

    private void initData() {
        //第二种写法
        Intent a=getIntent();

        String usernamea=a.getStringExtra("username");
        String contenta=a.getStringExtra("content");
        String timea=a.getStringExtra("time");

        username.setText(usernamea);
        content.setText(contenta);
        time.setText(timea);

      /*  Intent in=getIntent();
        String id=in.getStringExtra("id");
       // Post po=new Post();
        BmobQuery<Post> query=new BmobQuery<>();
        query.getObject(id, new QueryListener<Post>() {
            @Override
            public void done(Post post, BmobException e) {
                if(e==null){
                    username.setText(post.getName());
                    content.setText(post.getContent());
                    time.setText(post.getCreatedAt());
                }else{
                    Toast.makeText(Receive.this, "获取失败", Toast.LENGTH_SHORT).show();
                }
            }
        }); */
    }

    private void initView() {
        username=findViewById(R.id.username);
        content=findViewById(R.id.content);
        time=findViewById(R.id.time);
        back=findViewById(R.id.back);
    }
}
